package com.lanqiao.gxnushop.service;

import com.lanqiao.gxnushop.entity.Glance;
import com.lanqiao.gxnushop.mapper.GlanceMapper;
import com.lanqiao.gxnushop.util.UUIdUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Schema(description = "买家浏览服务")
@Service
public class GlanceService {
    @Autowired
    private GlanceMapper glanceMapper;
    @Autowired
    private BuyersService buyersService;

    @Schema(description = "添加浏览记录")
    public boolean add(Glance glance) {
        if(buyersService.findById(glance.getBuyerId())!=null){
            glance.setGlanceId(UUIdUtil.getUserId());
            return glanceMapper.add(glance);
        }
        return false;
    }

    @Schema(description = "删除浏览记录")
    public boolean delete(String glanceId) {
        return glanceMapper.delete(glanceId);
    }

    @Schema(description = "根据买家id查询浏览记录")
    public ArrayList<Glance> findByBuyerId(String buyerId) {
        return glanceMapper.findByBuyerId(buyerId);
    }

    @Schema(description = "根据浏览记录id查询浏览记录")
    public Glance findById(String glanceId) {
        return glanceMapper.findById(glanceId);
    }

    @Schema(description = "根据买家id和商品id查询浏览记录")
    public ArrayList<Glance> findByBuyerIdAndProductId(String buyerId, String productId) {
        return glanceMapper.findByBuyerIdAndProductId(buyerId, productId);
    }

    @Schema(description = "根据商品id查询浏览记录")
    public ArrayList<Glance> findByProductId(String productId) {
        return glanceMapper.findByProductId(productId);
    }
}
